package root.sport_manager.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import root.sport_manager.entity.po.User;
import root.sport_manager.service.UserService;
import root.sport_manager.tools.util.LayuiResultUtil;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author root
 * @since 2021-07-02
 */
@RestController
@RequestMapping("/sport_manager/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getUserList")
    public LayuiResultUtil<List> getUserList(){
        List<User> list = userService.list();
        return new LayuiResultUtil<>(0, "", userService.count(), list);
    }

    @GetMapping("/getUserById/{userId}")
    public LayuiResultUtil<User> getUserById(@PathVariable("userId")Integer userId){
        return new LayuiResultUtil<>(0,"success",1,userService.getById(userId));
    }

    @PostMapping("/addUser")
    public LayuiResultUtil<Integer> addUser(@RequestBody User user){
        return new LayuiResultUtil<Integer>(0,"success",1,userService.addUser(user));
    }
}

